package com.zmn.brs.task.listenter;

import com.alibaba.fastjson.JSONObject;
import com.zmn.brs.business.interfaces.record.OperateRecordNewBService;
import com.zmn.brs.common.constant.BrsMqConst;
import com.zmn.brs.common.enums.EventEnum;
import com.zmn.brs.common.model.mq.OperateRecordMq;
import com.zmn.manager.mq.annotation.AliyunMQHandler;
import com.zmn.manager.mq.annotation.AliyunMQListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 类描述：操作记录消息监听
 *
 * @author zhangyao
 * @since 2021/04/20 11:52
 */
@Slf4j
@Component
@AliyunMQListener(topic = "${spring.mq.topic.brs}")
public class OperateRecordMessageQueueListener {

    final static String TAG = "操作记录消息监听";

    @Resource
    OperateRecordNewBService operateRecordBusinessService;

    @AliyunMQHandler(topic = "${spring.mq.topic.brs}", tags = BrsMqConst.OPERATE_RECORD_MESSAGE)
    public void operateRecord(String message) {

        log.info("[{}],接收到新的消息message,原始消息:{}", TAG, message);
        OperateRecordMq recordMq = JSONObject.parseObject(message, OperateRecordMq.class);
        log.info("[{}],接收到新的消息message:{}", TAG, recordMq);
        if (recordMq.getPlat() != null) {
            // 转换事件编码
            EventEnum event = recordMq.getEvent();
            event = EventEnum.transformEventEnum(event, recordMq.getPlat().getCode());
            recordMq.setEvent(event);
        }
        operateRecordBusinessService.eventTriggering(recordMq);
    }

}
